package com.xyz.controller;

import com.xyz.aop.Param;
import com.xyz.entity.vo.EquipmentInfoExportVo;
import com.xyz.entity.vo.PartApplyExportVo;
import com.xyz.entity.vo.PartInfoExportVo;
import com.xyz.service.CommonService;
import com.xyz.service.PartService;
import com.xyz.util.BeanUtils;
import com.xyz.util.ExcelUtils;
import com.xyz.util.dto.DataResult;
import com.xyz.util.dto.GridData;
import com.xyz.util.dto.LoginInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("part")
public class PartController {

    private static final Logger logger = LoggerFactory.getLogger(PartController.class);

    @Autowired
    private PartService partService;

    @Autowired
    private CommonService commonService;

    @PostMapping("selectPartWarehouseLink")
    public DataResult selectPartWarehouseLink(
            LoginInfo li
    ) {
        try {
            return partService.selectPartWarehouseLink(li);
        } catch (Exception e) {
            logger.error("selectPartWarehouseLink", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartWarehouseLinkUnused")
    public DataResult selectPartWarehouseLinkUnused(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartWarehouseLinkUnused(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartWarehouseLinkUnused", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartStockLink")
    public DataResult selectPartStockLink(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartStockLink(
                    li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartStockLink", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPart")
    public DataResult selectPart(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String tech,
            @Param(isRequired = false) String codeOrName,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String nature,
            @Param(isRequired = false) String minPrice,
            @Param(isRequired = false) String maxPrice,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String minStock,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String maxStock,
            @Param(isRequired = false) String teamGroup
    ) {
        try {
            return partService.selectPart(
                    li, Integer.parseInt(pageNum), Integer.parseInt(pageSize),
                    tech, codeOrName, nature, minPrice, maxPrice, minStock, maxStock,teamGroup);
        } catch (Exception e) {
            logger.error("selectPart", e);
            return DataResult.build9500();
        }
    }

    @GetMapping("exportData")
    public DataResult exportData(
            LoginInfo li,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String tech,
            @Param(isRequired = false) String codeOrName,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String nature,
            @Param(isRequired = false) String minPrice,
            @Param(isRequired = false) String maxPrice,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String minStock,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String maxStock,
            @Param(isRequired = false) String teamGroup,
            HttpServletResponse response
    ) {
        try {
            DataResult dataResult = partService.selectPart(
                    li, 1, 2000,
                    tech, codeOrName, nature, minPrice, maxPrice, minStock, maxStock,teamGroup);
            Object obj = dataResult.getInfo();
            List<PartInfoExportVo> personList = new ArrayList<>();
            if (obj != null && obj instanceof GridData) {
                GridData gridData = (GridData) obj;
                personList = BeanUtils.toBean(gridData.getRows(), PartInfoExportVo.class);
                //实用性质
                Map<Integer, String> emGradeMap = commonService.getDictMap("TYPE_PART_NATURE");
                //工艺领域
                Map<Integer, String> emTypeMap = commonService.getDictMap("TYPE_PART_TECH");

                Map<Integer, String> teamGroupMap = commonService.getDictMap("TEAM_AND_GROUP");
                for (PartInfoExportVo vo : personList) {
                    vo.setNatureName(emGradeMap.get(vo.getNature()));
                    vo.setTechName(emTypeMap.get(vo.getTech()));
                    vo.setTeamGroupName(vo.getTeamGroup() == null ? "" : teamGroupMap.get(Integer.parseInt(vo.getTeamGroup())));
                }
            }
            ExcelUtils.write(response, "备件列表.xls", "备件", PartInfoExportVo.class,
                    personList);
            return DataResult.build9100();
        } catch (Exception e) {
            logger.error("exportData", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartInfo")
    public DataResult selectPartInfo(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartInfo(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartInfo", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertPartInfo")
    public synchronized DataResult insertPartInfo(
            LoginInfo li,
            @Param String code,
            @Param String name,
            @Param String specs,
            @Param String brand,
            @Param String unit,
            @Param String price,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String warnStock,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String maxStock,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String nature,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String tech,
            @Param String teamGroup,
            @Param String specification
    ) {
        try {
            return partService.insertPartInfo(
                    li, code, name, specs, brand, unit, price,
                    Integer.parseInt(warnStock),
                    Integer.parseInt(maxStock), Integer.parseInt(nature), Integer.parseInt(tech),
                    teamGroup,specification
            );
        } catch (Exception e) {
            logger.error("insertPartInfo", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updatePartInfo")
    public DataResult updatePartInfo(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param String code,
            @Param String name,
            @Param String specs,
            @Param String brand,
            @Param String unit,
            @Param String price,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String stock,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String warnStock,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String maxStock,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String nature,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String tech,
            @Param String teamGroup,
            @Param String specification
    ) {
        try {
            return partService.updatePartInfo(
                    li, Long.parseLong(id), code, name, specs, brand, unit, price,
                    Integer.parseInt(stock), Integer.parseInt(warnStock),
                    Integer.parseInt(maxStock), Integer.parseInt(nature), Integer.parseInt(tech),teamGroup,specification

            );
        } catch (Exception e) {
            logger.error("updatePartInfo", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deletePartInfo")
    public DataResult deletePartInfo(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.deletePartInfo(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("deletePartInfo", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartData")
    public DataResult selectPartData(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartData(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartData", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updatePartData")
    public DataResult updatePartData(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param(isRequired = false) String partDesc,
            @Param(isRequired = false) String fileCodes
    ) {
        try {
            return partService.updatePartData(li, Long.parseLong(id), partDesc, fileCodes);
        } catch (Exception e) {
            logger.error("updatePartData", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartEquipment")
    public DataResult selectPartEquipment(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartEquipment(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartEquipment", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertPartEquipment")
    public DataResult insertPartEquipment(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param String equipmentIds
    ) {
        try {
            return partService.insertPartEquipment(li, Long.parseLong(id), equipmentIds);
        } catch (Exception e) {
            logger.error("insertPartEquipment", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deletePartEquipment")
    public DataResult deletePartEquipment(
            LoginInfo li,
            @Param String ids
    ) {
        try {
            return partService.deletePartEquipment(li, ids);
        } catch (Exception e) {
            logger.error("deletePartEquipment", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartInOutLog")
    public DataResult selectPartInOutLog(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartInOutLog(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartInOutLog", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartTransitLog")
    public DataResult selectPartTransitLog(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartTransitLog(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartTransitLog", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartStock")
    public DataResult selectPartStock(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartStock(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartStock", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertPartStock")
    public synchronized DataResult insertPartStock(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String warehouse,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String locator
    ) {
        try {
            return partService.insertPartStock(li, Long.parseLong(id), Long.parseLong(warehouse), Long.parseLong(locator));
        } catch (Exception e) {
            logger.error("insertPartStock", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deletePartStock")
    public DataResult deletePartStock(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.deletePartStock(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("deletePartStock", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartDocument")
    public DataResult selectPartDocument(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartDocument(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartDocument", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertPartDocument")
    public DataResult insertPartDocument(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param String fileCodes
    ) {
        try {
            return partService.insertPartDocument(li, Long.parseLong(id), fileCodes);
        } catch (Exception e) {
            logger.error("insertPartDocument", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deletePartDocument")
    public DataResult deletePartDocument(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.deletePartDocument(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("deletePartDocument", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectStockInfo")
    public DataResult selectStockInfo(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectStockInfo(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectStockInfo", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertPartIn")
    public synchronized DataResult insertPartIn(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String inType,
            @Param String data
    ) {
        try {
            return partService.insertPartIn(li, Integer.parseInt(inType), data);
        } catch (Exception e) {
            logger.error("insertPartIn", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartApply")
    public DataResult selectPartApply(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false) String applyCode,
            @Param(isRequired = false) String state,
            @Param(isRequired = false) String minPartClass,
            @Param(isRequired = false) String maxPartClass,
            @Param(isRequired = false) String minPassTime,
            @Param(isRequired = false) String maxPassTime
    ) {
        try {
            return partService.selectPartApply(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), applyCode, state, minPartClass, maxPartClass, minPassTime, maxPassTime);
        } catch (Exception e) {
            logger.error("selectPartApply", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartApplyOne")
    public DataResult selectPartApplyOne(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartApplyOne(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartApplyOne", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertPartApply")
    public synchronized DataResult insertPartApply(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String outType,
            @Param(isRequired = false) String applyDesc,
            @Param(isRequired = false) String businessId,
            @Param(isRequired = false) String businessCode,
            @Param String data
    ) {
        try {
            return partService.insertPartApply(li, Integer.parseInt(outType), applyDesc, businessId, businessCode, data);
        } catch (Exception e) {
            logger.error("insertPartApply", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updatePartApply")
    public DataResult updatePartApply(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String outType,
            @Param(isRequired = false) String applyDesc,
            @Param String data
    ) {
        try {
            return partService.updatePartApply(li, Long.parseLong(id), Integer.parseInt(outType), applyDesc, data);
        } catch (Exception e) {
            logger.error("updatePartApply", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updatePartApplyState")
    public synchronized DataResult updatePartApplyState(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param(type = Param.ParamType.QUALIFIER, rule = "1,2,3,5,10,20") String operation,
            @Param(isRequired = false) String applyDesc
    ) {
        try {
            return partService.updatePartApplyState(li, Long.parseLong(id), Integer.parseInt(operation), applyDesc);
        } catch (Exception e) {
            logger.error("updatePartApplyState", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartApplyLog")
    public DataResult selectPartApplyLog(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartApplyLog(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartApplyLog", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartReview")
    public DataResult selectPartReview(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false) String applyCode,
            @Param(isRequired = false) String state
    ) {
        try {
            return partService.selectPartReview(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), applyCode, state);
        } catch (Exception e) {
            logger.error("selectPartReview", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartOrder")
    public DataResult selectPartOrder(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false) String orderCode,
            @Param(isRequired = false) String operationEmployeeName,
            @Param(isRequired = false) String businessCode,
            @Param(isRequired = false) String orderType,
            @Param(isRequired = false) String minOperationTime,
            @Param(isRequired = false) String maxOperationTime,
            @Param(isRequired = false) String inOutType,
            @Param(isRequired = false) String state
    ) {
        try {
            return partService.selectPartOrder(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), orderCode,
                    operationEmployeeName, businessCode, orderType, minOperationTime, maxOperationTime, inOutType, state);
        } catch (Exception e) {
            logger.error("selectPartOrder", e);
            return DataResult.build9500();
        }
    }



    @PostMapping("selectPartOrderByEm")
    public DataResult selectPartOrderByEm(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false) String orderCode,
            @Param(isRequired = false) String operationEmployeeName,
            @Param(isRequired = false) String businessCode,
            @Param(isRequired = false) String orderType,
            @Param(isRequired = false) String minOperationTime,
            @Param(isRequired = false) String maxOperationTime,
            @Param(isRequired = false) String inOutType,
            @Param(isRequired = false) String state) {
        try {
            return partService.selectPartOrderByUserId(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), orderCode,
                    operationEmployeeName, businessCode, orderType, minOperationTime, maxOperationTime, inOutType, state);
        } catch (Exception e) {
            logger.error("selectPartOrder", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("exportDataApply")
    public DataResult exportDataApply(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false) String orderCode,
            @Param(isRequired = false) String operationEmployeeName,
            @Param(isRequired = false) String businessCode,
            @Param(isRequired = false) String orderType,
            @Param(isRequired = false) String minOperationTime,
            @Param(isRequired = false) String maxOperationTime,
            @Param(isRequired = false) String inOutType,
            @Param(isRequired = false) String state,
            HttpServletResponse response
    ) {
        try {
            DataResult dataResult = partService.selectPartOrder(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), orderCode,
                    operationEmployeeName, businessCode, orderType, minOperationTime, maxOperationTime, inOutType, state);
            Object obj = dataResult.getInfo();
            List<PartApplyExportVo> personList = new ArrayList<>();
            if (obj != null && obj instanceof GridData) {
                GridData gridData = (GridData) obj;
                personList = BeanUtils.toBean(gridData.getRows(), PartApplyExportVo.class);
                //出入库类型
                Map<Integer, String> emGradeMap = commonService.getDictMap("TYPE_PART_OUT_TYPE");
                for (PartApplyExportVo vo : personList) {
                    if (vo.getState() == 0) {
                        vo.setStateName("未发起");
                    } else if (vo.getState() == 1) {
                        vo.setStateName("审批中");
                    } else if (vo.getState() == 2) {
                        vo.setStateName("审批通过");
                    } else if (vo.getState() == 3) {
                        vo.setStateName("审批驳回");
                    } else if (vo.getState() == 4) {
                        vo.setStateName("已出库");
                    }
                    if (vo.getOrderType() == 1) {
                        vo.setOrderTypeName("出库");
                    }else {
                        vo.setOrderTypeName("入库");
                    }
                    }
                }
            ExcelUtils.write(response, "备件出入库列表.xls", "备件出入库", PartApplyExportVo.class,
                    personList);

            return DataResult.build9100();
        } catch (Exception e) {
            logger.error("exportDataApply", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartOrderOne")
    public DataResult selectPartOrderOne(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String orderType,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartOrderOne(li, Integer.parseInt(orderType), Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartOrderOne", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertPartOut")
    public synchronized DataResult insertPartOut(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param String data,
            @Param(isRequired = false) String fileCodes
    ) {
        try {
            return partService.insertPartOut(li, Long.parseLong(id), data, fileCodes);
        } catch (Exception e) {
            logger.error("insertPartOut", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartInventory")
    public DataResult selectPartInventory(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false) String inventoryCode,
            @Param(isRequired = false) String state,
            @Param(isRequired = false) String result
    ) {
        try {
            return partService.selectPartInventory(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), inventoryCode, state, result);
        } catch (Exception e) {
            logger.error("selectPartInventory", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartInventoryOne")
    public DataResult selectPartInventoryOne(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartInventoryOne(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartInventoryOne", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPartWarehouseStock")
    public DataResult selectPartWarehouseStock(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String warehouse,
            @Param(isRequired = false) String codeOrName
    ) {
        try {
            return partService.selectPartWarehouseStock(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), warehouse, codeOrName);
        } catch (Exception e) {
            logger.error("selectPartWarehouseStock", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertPartInventory")
    public synchronized DataResult insertPartInventory(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String warehouse,
            @Param(isRequired = false) String remark,
            @Param(isRequired = false) String data
    ) {
        try {
            return partService.insertPartInventory(li, Long.parseLong(warehouse), remark, data);
        } catch (Exception e) {
            logger.error("insertPartInventory", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updatePartInventory")
    public DataResult updatePartInventory(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String warehouse,
            @Param(isRequired = false) String remark,
            @Param(isRequired = false) String data
    ) {
        try {
            return partService.updatePartInventory(li, Long.parseLong(id), Long.parseLong(warehouse), remark, data);
        } catch (Exception e) {
            logger.error("updatePartInventory", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deletePartInventory")
    public DataResult deletePartInventory(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.deletePartInventory(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("deletePartInventory", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updatePartInventoryStart")
    public DataResult updatePartInventoryStart(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.updatePartInventoryStart(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("updatePartInventoryStart", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updatePartInventoryData")
    public DataResult updatePartInventoryData(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param String data
    ) {
        try {
            return partService.updatePartInventoryData(li, Long.parseLong(id), data);
        } catch (Exception e) {
            logger.error("updatePartInventoryStart", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updatePartInventoryEnd")
    public DataResult updatePartInventoryEnd(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.updatePartInventoryEnd(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("updatePartInventoryEnd", e);
            return DataResult.build9500();
        }
    }


    @PostMapping("selectPartOrderOneByRepair")
    public DataResult selectPartOrderOneByRepair(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return partService.selectPartOrderOneByRepair(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectPartOrderOneByRepair", e);
            return DataResult.build9500();
        }
    }

}
